<?php

class VendorProducts extends Zend_Db_Table_Abstract
{
    protected $_name = 'vendor_products';
	
	public function setMenusForCaterer( &$menus, $caterer_id )
	{
		// delete where vendor_id == caterer_id and type == 'MENU'
		// insert
	}
	
	public function getMenusForCaterer( $caterer_id )
	{
		// fetchAll where vendor_id == caterer_id and type == 'MENU'
	}
	
	public function setArrangementsForFlorist( &$arrangements, $florist_id )
	{
		// delete where vendor_id == caterer_id and type == 'MENU'
		// insert
	}
	
	public function getArrangementsForFlorist( &$arrangements, $florist_id )
	{
		// fetchAll where vendor_id == florist_id and type == 'FLORAL'
	}
	
	public function getProductbyVASId( $productId )
	{
		$results = array();
		
		if(!isset($productId))
		{
			$results['status'] = "FAILED_BAD_PARAM";
			return $results;
		}
		
		try
		{
			$rr = $this->fetchRow('id=$productId');
			
			$results['status'] = "SUCCEEDED";
			$results['rows'] = array( $rr->toArray() );
		}
		catch(Exception $e)
		{
			$results['status'] = "FAILED";
			$results['rows'] = array();
		}
		
		return $results;	
	}
	
	public function getProductByFDMSCode( $fdmsCode )
	{
	}
	
	public function getProductsForVendor( $vendorId )
	{		
		$results = array();
		
		if(!isset($vendorId))
		{
			$results['status'] = "FAILED_BAD_PARAM";
			return $results;
		}
		
		try
		{
			$rr = $this->fetchAll('vendor_id=$vendorId');
			
			$results['status'] = "SUCCEEDED";
			$results['rows'] = array();
			foreach( $rr as $row )
				$results['rows'][] = $row->toArray();				
		}
		catch(Exception $e)
		{
			$results['status'] = "FAILED";
			$results['rows'] = array();
		}
		
		return $results;	
	}	
	
	public function addProduct( $product_info, $vendorId )
	{
		$results = array();
		
		if(!isset($vendorId) || !isset($product_info))
		{
			$results['status'] = "FAILED_BAD_PARAM";
			return $results;
		}
		
		try
		{
			$rr = $this->insert( $product_info );
			if($rr)
			{
				$results['status'] = "SUCCEEDED";
				$results['affected_rows'] = 1;
			}
		}
		catch(Exception $e)
		{
			$results['status'] = "FAILED";
			$results['rows'] = array();
		}
		
		return $results;	
	}
	
	public function updateProduct( $productId, $product_info )
	{
		$results = array();
		
		if(!isset($productId) || !isset($product_info))
		{
			$results['status'] = "FAILED_BAD_PARAM";
			return $results;
		}
		
		try
		{
			$rr = $this->update( $product_info, "id=$productId" );
			if($rr)
			{
				$results['status'] = "SUCCEEDED";
				$results['affected_rows'] = 1;
			}
		}
		catch(Exception $e)
		{
			$results['status'] = "FAILED";
			$results['rows'] = array();
		}
				
		return $results;	
	}
}

?>
